    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/public/header/permissionCommon.jspf" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="itheima" uri="http://ChanghuXian.com/common/"%>


<html>
<head>
    <title>被护理老人统计</title>
    <link href="${webPath}/css/Sign/bootstrap.min.css" rel="stylesheet">
    <%@include file="/resources/commons/basejs.jsp" %>
</head>
<body class="layui-layout-body" onload="load()">
<div class="layui-layout layui-layout-admin">
    <!-- 头部和左侧导航-->
    <div id="header"></div>

    <!--右侧主体区域-->
    <div class="layui-body" >
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this">被护理老人统计</li>

            </ul>
            <div class="layui-tab-content">
                <%-----------被护理老人统计表-----------%>
                <div id="elderDiv" class="layui-tab-item layui-show">

                <%----------- 信息表格 显示------------%>
                    <table class="layui-hide" id="showelder" lay-filter="elder" ></table>
                    <%--搜索年份--%>
                    <div class="SearchLoadDepartment" style="font-size: small">
<%--                        搜索年份：--%>
                        <div class="layui-input-inline layui-show div-inline" style="width: 100%;">
<%--                            <select name="yearSearch" id="yearSearch" lay-filter="yearSearch" class="select">--%>
<%--                                <option value="">请选择年份</option>--%>
<%--                                <option value="2021">2021年</option>--%>
<%--                                <option value="2020">2020年</option>--%>
<%--                                <option value="2019">2019年</option>--%>
<%--                            </select>--%>
                            <%--任意时间段查询--%>
                            <form id="userSearch" class="layui-form layui-form-pane layui-input-inline" method="post"
                                  style="margin-top: 20px; width:70%">
                                <div class="layui-form-item" style="width:100%">

                                    <label class="layui-form-label" style="width: auto">时间</label>
                                    <div class="layui-input-inline" style="width: auto">
                                        <%--<input type="date" class="layui-input" id="timeStart" placeholder="yyyy-MM-dd HH:mm:ss">--%>
                                        <input name="timeStart" id="timeStart" placeholder="开始时间"
                                               autocomplete="off" class="layui-input"/>
                                    </div>
                                    <div class="layui-form-mid">-</div>
                                    <div class="layui-input-inline" style="width: auto">
                                        <input name="timeEnd" id="timeEnd" placeholder="结束时间"
                                               autocomplete="off" class="layui-input"/>
                                    </div>

                                    <label class="layui-form-label" style="width: auto">搜索护理机构</label>
                                    <div class="layui-input-inline" style="width: auto" >
                                        <select name="getServorg" id="getServorg" lay-filter="getServorg"  class="select">
                                            <option value="">请选择护理机构</option>
                                        </select>
                                    </div>

                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    <%--这里要改下--%>
                                    <button class="layui-btn" lay-submit lay-filter="searchSubmit" style="width: auto">
                                        <i class="layui-icon">&#xe615;</i>查询
                                    </button>
                                </div>
                            </form>
                            <div class="layui-inline" style="float: right;margin-top: 20px; ">
                                <button class="layui-btn " id="exportExcel" name="exportExcel" style="width: auto;float: right;border-radius: 5px;margin-left: 5px;">
                                    <%--                            <button class="layui-btn layui-btn-sm" id="exportExcel" name="exportExcel" style="width: 100px;float: right;border-radius: 5px;margin-left: 5px">--%>
                                    <i class="layui-icon layui-icon-export"></i>
                                    <div class="layui-inline" style="font-size: small;text-align:center;margin-top: -3px">导出文件</div>
                                </button>
                            </div>

                        </div>

<%--                        <div class="layui-inline">--%>
<%--                            <button class="searchBtn" data-type="reload1" style="margin-left:10px;height:30px;width:85px;background-color: #009688;color: white;border: none;border-radius: 5px">--%>
<%--                                <i class="layui-icon layui-icon-search"></i>--%>
<%--                                <div class="layui-inline" style="font-size: small;text-align:center;margin-top: -6px;margin-left: 5px;margin-right: 5px">搜 索</div>--%>
<%--                            </button>--%>
<%--                        </div>--%>
                        <%-------------文件导出-------------%>
<%--                        <div class="layui-inline" style="float: right">--%>
<%--                            <button class="layui-btn " id="exportExcel" name="exportExcel" style="width: auto;float: right;border-radius: 5px;margin-left: 5px;">--%>
<%--&lt;%&ndash;                            <button class="layui-btn layui-btn-sm" id="exportExcel" name="exportExcel" style="width: 100px;float: right;border-radius: 5px;margin-left: 5px">&ndash;%&gt;--%>
<%--                                <i class="layui-icon layui-icon-export"></i>--%>
<%--                                <div class="layui-inline" style="font-size: small;text-align:center;margin-top: -3px">导出文件</div>--%>
<%--                            </button>--%>
<%--                        </div>--%>
                    </div>
<%--                    <table class="layui-hide" id="showyearall" lay-filter="year" ></table>--%>

<%--                    <div style="color:transparent;margin-top: 4%">-</div>--%>
                    <%--任意时间段查询表格--%>
                    <table class="layui-hide" id="showyear" lay-filter="year" ></table>
<%--                    统计表格--%>
                    <table class="layui-hide" id="showtongji" lay-filter="tongji" ></table>

                </div>
            </div>
        </div>
    </div>

    <!--底部-->
    <div id="footer"></div>
</div>
    <script>
        $("#header").load("${webPath}/publicPages/permission/fragments/header.jsp");
        $("#footer").load("${webPath}/publicPages/permission/fragments/footer.jsp");
    </script>
    <script type="text/javascript" src="${webPath}/js/permission/dateUtils.js"></script>
    <script type="text/javascript" src="${webPath}/js/StatisticalReport/elder.js"></script>

    <%------------------- EXCEL 文件导出------------------%>
    <script type="text/javascript">
        layui.use(['form',"table","laydate"], function(){
            var form = layui.form,
                table =layui.table,
                laydate =layui.laydate;

            //下拉框动态加入护理机构
            $.ajax({
                type:"POST",
                url:'../statistics/getServorg',  //从数据库查询返回的是个list
                success: function (data) {
                    console.log("护理机构查询", data);
                    $.each(data,function(index,item){
                        $('#getServorg').append(new Option(item.serv_org));//往下拉菜单里添加元素
                    })
                    form.render();//菜单渲染 把内容加载进去
                }
                ,error: function () {
                    alert("查询机构失败！！！")}

            })

            form.on('submit(searchSubmit)', function(data){

                data.field.page= 1;
                data.field.limit = 10;
                console.log('hello',data.field);
                //刷新任意时间段查询的表格
                $.ajax({

                    url:"/statistics/selectByElder",
                    // url:"/statistics/selectEldertime",
                    data:data.field,
                    request: {
                        pageName: 'page' //页码的参数名称，默认：page
                        ,limitName: 'limit' //每页数据量的参数名，默认：limit
                    },
                    type:"POST",
                    success:function(data){
                        // console.log("xxxxxx",data.list);
                        console.log("xxxxxx",data);
                        console.log("yyyyyy",data.field);
                        table.reload('year',{
                            url:"",
                            // data:data.list,
                            data:data,
                            done: function(){
                                console.log("完成")
                            }
                        })
                    },//ajax的使用，点击submit即可跳转到controller处寻找url完成功能

                });

                //刷新统计合计的表格
                $.ajax({

                    url:"/statistics/fuwushuSum",
                    data:data.field,
                    request: {
                        pageName: 'page' //页码的参数名称，默认：page
                        ,limitName: 'limit' //每页数据量的参数名，默认：limit
                    },
                    type:"POST",
                    success:function(data){
                        // console.log("xxxxxx",data.list);
                        console.log("xxxxxx",data);
                        console.log("yyyyyy",data.field);
                        table.reload('tongji',{
                            url:"",
                            // data:data.list,
                            data:data,
                            done: function(){
                                console.log("完成")
                            }
                        })
                    },//ajax的使用，点击submit即可跳转到controller处寻找url完成功能

                });

                return false;
            });
            //日期
            laydate.render({
                elem: '#timeStart',
                type: 'month'
            });
            laydate.render({
                elem: '#timeEnd',
                type: 'month'
            });
        })

        layui.config({//配置并导入excel插件
            base: '${base}/js/layui_exts/'
        }).use([ 'excel', 'layer'], function() {
            var $ = layui.$;
            var layer = layui.layer;
            var excel = layui.excel;
            $('#exportExcel').on('click', function(){
                console.log("触发导出按钮");
                var timeStart = $('#timeStart');
                var timeEnd = $('#timeEnd');
                var serv_org = $('#getServorg');
                // var year = $('#year');

                layer.confirm('是否确认导出', function(index) {
                    $.ajax({
                        url:'../statistics/selectByElder'
                        // url:'../statistics/listElderyear'
                        ,method:'post'
                        ,data: {
                            // year: year.val(),
                            timeStart: timeStart.val(),
                            timeEnd: timeEnd.val(),
                            getServorg:serv_org.val(),
                        }
                        , dataType: 'json'
                        , success(res) {
                            var data = res;
                            console.log(res);
                            layer.close(index);
                            data = excel.filterExportData(data, [
                                'time'
                                ,'serv_org'
                                , 'fuwushu'
                                , 'leijishu'
                                , 'youxiaozhengchang'
                                , 'youxiaozanting'
                                , 'wuxiaoqushi'
                                , 'lr_wuxiaozhuanchu'
                            ]);
                            data.unshift({
                                time: "月份", serv_org:"护理站",fuwushu: "服务人次",
                                leijishu: '累计数', youxiaozhengchang: "有效正常",
                                youxiaozanting: "有效暂停", wuxiaoqushi: "无效去世",
                                lr_wuxiaozhuanchu: "无效转出"
                            });
                            excel.exportExcel(data, '被护理老人状态统计导出--' + new Date().toLocaleString() + '.xlsx', 'xlsx');
                        }
                        , error() {
                            layer.alert('获取数据失败，请检查是否部署在本地服务器环境下');
                        }
                    });
                });
            });
        });
    </script>


</body>



</html>
